feat(integrations): Add http.route attribute to server spans - #7183
Conversation
Codecov Results 📊✅ 118671 passed | ⏭️ 6732 skipped | Total: 125403 | Pass Rate: 94.63% | Execution Time: 413m 31s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 98.15%. Project has 2478 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 90.23% 90.29% +0.06%
==========================================
Files 193 193 —
Lines 25482 25527 +45
Branches 9384 9408 +24
==========================================
+ Hits 22994 23049 +55
- Misses 2488 2478 -10
- Partials 1431 1430 -1Generated by Codecov Action |
dddf367 to
b1363a5
Compare
…#7201) The sync request/response handler passed the _isolation_ scope to `_set_transaction_name_and_source`, but the transaction/segment span lives on the _current_ scope. As a result the route-resolved name never reached the span for sync endpoints, which were instead named by the raw URL from the ASGI middleware (`transaction_info.source` of `url` rather than `route`). Async handlers already used the current scope and were unaffected. Pass the current scope (already computed above) so sync and async handlers behave identically: - streaming: the segment name / `sentry.segment.name.source` are route-based - static: the transaction event name / source are route-based For parametrized routes this also removes high-cardinality URL transaction names for sync endpoints. Found while working on #7183.
…#7201) The sync request/response handler passed the _isolation_ scope to `_set_transaction_name_and_source`, but the transaction/segment span lives on the _current_ scope. As a result the route-resolved name never reached the span for sync endpoints, which were instead named by the raw URL from the ASGI middleware (`transaction_info.source` of `url` rather than `route`). Async handlers already used the current scope and were unaffected. Pass the current scope (already computed above) so sync and async handlers behave identically: - streaming: the segment name / `sentry.segment.name.source` are route-based - static: the transaction event name / source are route-based For parametrized routes this also removes high-cardinality URL transaction names for sync endpoints. Found while working on #7183.
b1363a5 to
1d15a6d
Compare
http.route attribute to HTTP server spans| for attribute, value in attributes.items(): | ||
| self.set_attribute(attribute, value) | ||
|
|
||
| def set_segment_attribute(self, key: str, value: "AttributeValue") -> None: |
There was a problem hiding this comment.
This seemed like a useful helper function to have (and avoids duplicating this code in every HTTP integration), but I would also understand if we don't want to expand the API surface with this: it makes the "segment" name a public thing which AIUI we are trying to avoid?
### Description When host routing, we don't have a route and instead fall back to the request path for the transaction name. This should be given transaction source `url` (for raw URLs) instead of the current value of `route` (for parameterized routes). This matters for #7183, where the mis-categorized transaction source would lead to bad data in `http.route`. (Bug found by Cursor in #7183 (comment) when reviewing that PR).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fdd83b4. Configure here.
| if http_route is not None: | ||
| current_span._segment.set_attribute( | ||
| SPANDATA.HTTP_ROUTE, http_route | ||
| ) |
There was a problem hiding this comment.
Aiohttp skips scope transaction update
Medium Severity
Switching to traces.get_current_span() makes the streaming branch actually run, but that path only mutates the span and never calls set_transaction_name. Error events still read the scope’s _transaction, which stays at the generic fallback, so captured exceptions can be grouped and linked under the wrong name.
Reviewed by Cursor Bugbot for commit fdd83b4. Configure here.


Description
Currently the HTTP path template is only available in the span name. Make it available as a semantic attribute as well (
http.route- definition in conventions).This will also let us use this in e.g. HTTP server span
descriptiongeneration, which will be necessary to maintain consistent descriptions between transactions and span streaming.Issues
http.routemissing from HTTP server spans #7182